script_enemy_main{

let shot1=0;
let bullet1=[];
let timer1=[];
let angle1=[];
let speed1=[];
let size1=[];

let shot2=0;
let bullet2=[];
let timer2=[];

let shot3=0;
let bullet3=[];
let timer3=[];

let shot4=0;
let bullet4=[];
let timer4=[];
let angle4=[];

let effect1=0;
let object1=[];

let shoottime=200;
let angle=rand(0,360);
let locx=0;
let locy=0;
let dead=0;
let size=0;

let character="Hotaru";
let cutin=character;
let spellcards=11;
let spellcardnumber=47;
let dispelled=0;
let damagerate=10;
let outfit=5;
outfit=(128*outfit)-128;
let usespell=0;
let bgfade=0;
let frame=0;
let time=0;
let miny=GetClipMinY; let maxy=GetClipMaxY; let minx=GetClipMinX; let maxx=GetClipMaxX;
let cx=GetCenterX; let cy=GetCenterY;

let SEexplodes1=("script\SoundEffects\explodes1.wav");
let SEshotb5=("script\SoundEffects\shotb5.wav");

let GReffect=("\script\Images\OtherEffects\SpellCircle1b.png");
let BG1=("\script\Images\BackgroundLayers\Hotaru1.png");
let BG2=("\script\Images\BackgroundLayers\Hotaru2.png");
let GRboss=("\script\Images\CharacterSprites\Hotaru.png");

#include_function "script/Functions/SetSpellcardCommonData.txt";
#include_function "script/Functions/SpellcardNameLoad.txt";
#include_function "script/Functions/HealthBarLoad.txt";
#include_function "script/Functions/CutInLoad.txt";

@Initialize{
	LoadUserShotData("script\shots\ShotsHotaru1.txt");

	LoadGraphic("\script\Images\OtherEffects\SpellCircle1b.png");
	LoadGraphic("\script\Images\BackgroundLayers\Hotaru1.png");
	LoadGraphic("\script\Images\BackgroundLayers\Hotaru2.png");
	LoadGraphic("\script\Images\CharacterSprites\Hotaru.png");

	LoadSE("script\SoundEffects\explodes1.wav");
	LoadSE("script\SoundEffects\shotb5.wav");

	SetScore(750000);
	SetLife(500);
	SetTimer(60);
	SetInvincibility(90);
	SetDamageRate(10,10); 
	SetEnemyMarker(true);
	MagicCircle(true);
	#include_function "script/Functions/Focus.txt";
	Focus(character);
	SetEffectForZeroLife(60,100,1);
	SetMovePosition02(cx,miny+100,50);

	SetX(GetCommonData("Boss1X"));
	SetY(GetCommonData("Boss1Y"));
	SetCommonData("Boss1Vanish",1);
}
	
@MainLoop{

SetCollisionA(GetX,GetY,16);
SetCollisionB(GetX,GetY,16);
SetShotAutoDeleteClip(128,128,128,128);

Weakness(character);
#include_function "script/Functions/Weakness.txt";
if(GetCommonData("BombOn")==0){ damagerate=10;  if(GetTimer<=35){ damagerate=25; } }
if(GetCommonData("BombOn")==1){ damagerate=2.5; }
SetDamageRate(damagerate*weaken,damagerate*weaken);

let difficulty="";
if(GetCommonDataDefault("Difficulty",2)==1){ difficulty="Easy"; }
if(GetCommonDataDefault("Difficulty",2)==2){ difficulty="Normal"; }
if(GetCommonDataDefault("Difficulty",2)==3){ difficulty="Hard"; }
if(GetCommonDataDefault("Difficulty",2)==4){ difficulty="Lunatic"; }
SpellcardName("Ignition [The Fire Tetrahedron]",spellcardnumber); 

HealthBar();
Portrait(cutin,2);

if(time%80==0 && time>=60){
	if(GetPlayerX>minx+50 && GetPlayerX<maxx-50){
	SetMovePosition01(GetPlayerX+rand(-30,30),rand(miny+80,miny+100),1.5);
	}
	if(GetPlayerX<=minx+50){
	SetMovePosition01(GetPlayerX+rand(15,30),rand(miny+80,miny+100),1.5);
	}
	if(GetPlayerX>=maxx-50){
	SetMovePosition01(GetPlayerX-rand(15,30),rand(miny+80,miny+100),1.5);
	}
}


if(time==0){
let xsize=200;
let ysize=200;
let nr=1;
	loop(3){
	effect1=(Obj_Create(OBJ_EFFECT));
	Obj_SetPosition(effect1,GetPlayerX+0*cos(angle),GetPlayerY+0*sin(angle));
	ObjEffect_SetAngle(effect1,0,0,angle); ObjEffect_SetScale(effect1,0.25,0.25);
	ObjEffect_SetLayer(effect1,3); ObjEffect_SetTexture(effect1,GReffect); ObjEffect_SetRenderState(effect1,ADD);
	ObjEffect_SetPrimitiveType(effect1,PRIMITIVE_TRIANGLESTRIP); ObjEffect_CreateVertex(effect1,4);
	ObjEffect_SetVertexXY(effect1,0,-(xsize/2),-(ysize/2)); ObjEffect_SetVertexUV(effect1,0,0,0);
	ObjEffect_SetVertexXY(effect1,1,xsize/2,-(ysize/2)); ObjEffect_SetVertexUV(effect1,1,xsize,0);
	ObjEffect_SetVertexXY(effect1,2,-(xsize/2),ysize/2); ObjEffect_SetVertexUV(effect1,2,0,ysize);
	ObjEffect_SetVertexXY(effect1,3,xsize/2,ysize/2); ObjEffect_SetVertexUV(effect1,3,xsize,ysize);
	if(nr==1){
	ObjEffect_SetVertexColor(effect1,0,255,50,50,255); ObjEffect_SetVertexColor(effect1,1,255,50,50,255);
	ObjEffect_SetVertexColor(effect1,2,255,50,50,255); ObjEffect_SetVertexColor(effect1,3,255,50,50,255);
	}
	if(nr==2){
	ObjEffect_SetVertexColor(effect1,0,255,50,255,50); ObjEffect_SetVertexColor(effect1,1,255,50,255,50);
	ObjEffect_SetVertexColor(effect1,2,255,50,255,50); ObjEffect_SetVertexColor(effect1,3,255,50,255,50);
	}
	if(nr==3){
	ObjEffect_SetVertexColor(effect1,0,255,255,50,50); ObjEffect_SetVertexColor(effect1,1,255,255,50,50);
	ObjEffect_SetVertexColor(effect1,2,255,255,50,50); ObjEffect_SetVertexColor(effect1,3,255,255,50,50);
	}
	object1=object1~[effect1];
	angle+=120;
	nr++;
	}

let angle2=atan2(GetPlayerY-Obj_GetY(object1[2]),GetPlayerX-Obj_GetX(object1[2]));
	loop(3){
	shot4=(Obj_Create(OBJ_LASER));
	Obj_SetPosition(shot4,GetPlayerX,GetPlayerY);
	Obj_SetAngle(shot4,angle2);
	Obj_SetSpeed(shot4,0);
	ObjShot_SetDelay(shot4,10000);
	Obj_SetAutoDelete(shot4,false);
	ObjLaser_SetLength(shot4,50);
	ObjLaser_SetWidth(shot4,10);
	ObjLaser_SetSource(shot4,false);
	ObjShot_SetGraphic(shot4,121);
	bullet4=bullet4~[shot4];
	timer4=timer4~[shot4];
	timer4[length(bullet4)-1]=0;
	angle4=angle4~[shot4];
	angle4[length(bullet4)-1]=Obj_GetAngle(shot4);
	angle2+=180;
	}
}

let i=0;
	loop(3){
	Obj_SetPosition(object1[i],GetPlayerX+size*cos(angle),GetPlayerY+size*sin(angle));
	ObjEffect_SetAngle(object1[i],0,0,time*4);
	Obj_SetAngle(object1[i],angle);
	angle+=120;
	i++;
	}
angle--;
if(time<150){ size+=1; }
if(size>70){ size-=0.03; }


let i=0;
let angle2=atan2(GetPlayerY-Obj_GetY(object1[2]),GetPlayerX-Obj_GetX(object1[2]));
	loop(3){
	ObjLaser_SetLength(bullet4[i],size*1.75);
	Obj_SetPosition(bullet4[i],GetPlayerX+size*cos(angle),GetPlayerY+size*sin(angle));
	Obj_SetAngle(bullet4[i],angle+150);
	angle4[i]=angle4[i]+1;
	timer4[i]=timer4[i]+1;
	angle+=120;
	i++;
	}


if(frame==shoottime){
dead=0;
locx=GetPlayerX;
locy=GetPlayerY;

let angle2=Obj_GetAngle(object1[1])-180;
loop(3){
	loop(6){
	shot2=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot2,Obj_GetX(object1[0]),Obj_GetY(object1[0]));
	Obj_SetAngle(shot2,angle2+rand(-20,20));
	Obj_SetSpeed(shot2,rand(0.8,1.2)*size/100);
	ObjShot_SetGraphic(shot2,80);
	ObjShot_SetDelay(shot2,10);
	bullet2=bullet2~[shot2];
	timer2=timer2~[shot2];
	timer2[length(bullet2)-1]=0;
	}
angle2+=360/3;
}

let angle2=Obj_GetAngle(object1[1])-180;
	loop(7){
	shot2=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot2,Obj_GetX(object1[1]),Obj_GetY(object1[1]));
	Obj_SetAngle(shot2,angle2);
	Obj_SetSpeed(shot2,1*size/100);
	ObjShot_SetGraphic(shot2,65);
	ObjShot_SetDelay(shot2,10);
	bullet2=bullet2~[shot2];
	timer2=timer2~[shot2];
	timer2[length(bullet2)-1]=0;
	angle2+=360/7;
	}

let angle2=atan2(GetPlayerY-Obj_GetY(object1[2]),GetPlayerX-Obj_GetX(object1[2]))-15;
	loop(3){
		loop(2){
		shot1=(Obj_Create(OBJ_LASER));
		Obj_SetPosition(shot1,Obj_GetX(object1[2]),Obj_GetY(object1[2]));
		Obj_SetAngle(shot1,angle2);
		Obj_SetSpeed(shot1,1.2*size/100);
		ObjShot_SetDelay(shot1,10);
		ObjLaser_SetLength(shot1,0);
		ObjLaser_SetWidth(shot1,10);
		ObjLaser_SetSource(shot1,false);
		ObjShot_SetGraphic(shot1,85);
		bullet1=bullet1~[shot1];
		timer1=timer1~[shot1];
		timer1[length(bullet1)-1]=0;
		speed1=speed1~[shot1];
		speed1[length(bullet1)-1]=Obj_GetSpeed(shot1);
		angle1=angle1~[shot1];
		angle1[length(bullet1)-1]=Obj_GetAngle(shot1);
		size1=size1~[shot1];
		size1[length(bullet1)-1]=0;
		angle2+=180;
		}
	angle2+=15;
	}
PlaySE(SEshotb5);
}

let i=0;
while(i<length(bullet1)){
	if(Obj_BeDeleted(bullet1[i])){
	bullet1=erase(bullet1,i); timer1=erase(timer1,i); speed1=erase(speed1,i); angle1=erase(angle1,i); size1=erase(size1,i);
	i--;
	}
	else{
	ObjLaser_SetLength(bullet1[i],size1[i]);

	if(size1[i]<50){ Obj_SetPosition(bullet1[i],Obj_GetX(bullet1[i])+0*cos(angle1[i]),Obj_GetY(bullet1[i])+0*sin(angle1[i])); }
	if(size1[i]>=50){ Obj_SetPosition(bullet1[i],Obj_GetX(bullet1[i])+speed1[i]*cos(angle1[i]),Obj_GetY(bullet1[i])+speed1[i]*sin(angle1[i])); }
	if(size1[i]<50){ size1[i]=size1[i]+1; }
	timer1[i]=timer1[i]+1;
	}
i++;
}

let i=0;
while(i<length(bullet2)){
	if(Obj_BeDeleted(bullet2[i])){
	bullet2=erase(bullet2,i); timer2=erase(timer2,i);
	i--;
	}
	else{
	timer2[i]=timer2[i]+1;
	}
i++;
}

let i=0;
while(i<length(bullet3)){
	if(Obj_BeDeleted(bullet3[i])){
	bullet3=erase(bullet3,i); timer3=erase(timer3,i);
	i--;
	}
	else{
	timer3[i]=timer3[i]+1;
	}
i++;
}


if(frame==90 && time>90 && dead==0){
let anglez=rand(0,360);
	loop(150){
	let radiusz=rand(5,25);
	CreateShot02(locx+radiusz*cos(anglez+rand(-60,60)),locy+radiusz*sin(anglez+rand(-60,60)),rand(1.5,3),anglez+rand(-5,5),-0.04,rand(0.4,1.2),rand_int(25,27),rand_int(10,20));
	anglez+=360/120;
	}
PlaySE(SEexplodes1);
}

if(frame==shoottime){ frame=0; if(shoottime>120){ shoottime-=5; } }

if(OnPlayerMissed==true){
dead=1;
let i=0;
	while(i<length(bullet1)){
	ObjShot_FadeDelete(bullet1[i]);
	i++;
	}
frame=60;
}


time++; frame++;
if(usespell>0){ usespell--; } if(usespell<0){ usespell++; }
SetCommonData("Boss1X",GetX); SetCommonData("Boss1Y",GetY);

#include_function "script/Functions/SpellcardName.txt";
#include_function "script/Functions/HealthBar.txt";
#include_function "script/Functions/CutIn.txt";

if(GetLife==0 && dispelled==0){ CreateEnemyFromFile("script\Functions\dispel.txt",GetX,GetY,0,0,character); dispelled=1; }
}

@BackGround{
	if(bgfade<255){ bgfade+=5; }

	SetGraphicRect(0,0+time,300,300+time);
	SetGraphicScale(2+0.3*cos(time),2-0.3*cos(time));
	SetTexture(BG1);
	SetAlpha(bgfade);
	SetColor(130,130,130);
	SetRenderState(ALPHA);
	SetGraphicAngle(0,0,0);
	DrawGraphic(cx,cy);
	
	SetGraphicRect(0-time,0-time/2,300-time,300-time/2);
	SetGraphicScale(2,2);
	SetTexture(BG2);
	DrawGraphic(cx,cy);
}

@DrawLoop{
	SetGraphicScale(1,1);
	SetTexture(GRboss);
	SetGraphicAngle(0,0,0);
	SetColor(255,255,255);
	SetRenderState(ALPHA);

	if(usespell>=1){ SetGraphicRect(384,outfit,512,outfit+128); }
	if(usespell<=-1){ SetGraphicRect(512,outfit,640,outfit+128); }
	if(usespell==0){
		if(GetSpeedX<=0.5 && GetSpeedX>=-0.5){ SetGraphicRect(0,outfit,128,outfit+128); }
		else if(GetSpeedX<-0.5){ SetGraphicRect(128,outfit,256,outfit+128); }
		else if(GetSpeedX>0.5){ SetGraphicRect(256,outfit,384,outfit+128); }
	}
	DrawGraphic(GetX,GetY);
}

@Finalize{
//	SetCommonData("Conversation",1);
	NewPointData(spellcardnumber,5);
	#include_function "script/Functions/Main Menu/SpellcardDataAndPoints.txt";
}

}